import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class HttpService {

  constructor(public http: HttpClient) { }

  get(url: string): Observable<Object> {
    return this.http.get(url)
  }

  post(url: string, body: {[key: string]: any}): Observable<Object> {
    return this.http.post(url, body, {
      headers: new HttpHeaders({
        'Content-type': 'application/json',
        'token': ''
      })
    })
  }

  // 使用jsonp需要服务器接口支持jsonp
  /**
   * http://a.itying.com/api/productlist?callback=xxx
   * http://a.itying.com/api/productlist?cb=xxx
   */
  jsonp(url: string, callbackParam: string): Observable<Object> {
    return this.http.jsonp(url, callbackParam)
  }
}
